package com.rutong.study;

import android.util.Log;

import androidx.lifecycle.LiveData;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;

public class MyLiveData extends LiveData<String> {
    Disposable disposable;

    @Override
    protected void onActive() {
        super.onActive();
        Log.i("rutong", "onActive");
        disposable = Observable.interval(2, TimeUnit.SECONDS).subscribe(aLong ->
                postValue(aLong.toString())
        );
    }

    @Override
    protected void onInactive() {
        super.onInactive();
        Log.i("rutong", "onInactive");
        disposable.dispose();
    }


}
